package com.ianmoone.JZOF;

import java.util.HashSet;
import java.util.Scanner;

public class S360Test2 {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int m = in.nextInt();
		int[] a = new int[n];
		in.nextLine();
		String string = in.nextLine();
		String[] split = string.split(" ");
		for (int i = 0; i < split.length; i++) {
			a[i] = Integer.valueOf(split[i]);
		}
		int q = in.nextInt();
		in.nextLine();
		for (int i = 0; i < q; i++) {
			HashSet<Integer> set = new HashSet<>();
			string = in.nextLine();
			split = string.split(" ");
			int o = Integer.valueOf(split[0]);
			int p = Integer.valueOf(split[1]);
			for (int j = o-1; j < p; j++) {
				set.add(a[j]);
			}
			System.out.println(set.size());
		}
	}
}
